<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{fragment/header :: header}"></th:block>
    <meta charset="UTF-8">
    <title>Contest</title>
    <style>
        .ui.fluid.container {
            max-width: 85% !important;
        }
    </style>
</head>
<body>
<main class="ui container fluid" id="contest-content">
    <div class="segment">
        <div class="header" v-if="info.length==0">Waiting...</div>
        <h1 class="ui center aligned header" v-html="info"></h1>
        <a :href="'/contest/edit/'+cid" class="ui button" v-if="creator">Update更新比赛</a>
    </div>
</main>
<script>
    var cid = location.pathname.split('/');
    cid = cid[cid.length - 1];
    var cont = new Vue({
        el: "#contest-content",
        data: {
            info: "",
            cid: cid,
            creator: false
        },
        created() {
            var that = this;
            axios.get('/api/contest/gate/' + cid)
                .then(function (response) {
                    let res = response.data;
                    if (res == "success") {
                        location.href = "/contest/problem/" + cid;
                        return;
                    }
                    alert(res);
                    that.info = res;
                })
                .catch(function (e) {
                    console.log(e);
                    if (e.response.status == 404) {
                        location.href = "/4O4";
                    }
                });
            axios.get("/api/contest/background/access/" + cid)
                .then(function (res) {
                    if (res.data == "success") {
                        that.creator = true;
                    }
                }).catch(function (e) {
                console.log(e)
            });
        }
    });
</script>
<footer th:replace="~{fragment/footer :: footer}"></footer>
</body>
</html>